import { toolchain } from "../../toolchain.js";
import { BaseTask, TaskResult } from "./BastTask.js";

/**
 * 设置脚本宏。
 */
export class SetScriptDefineTask extends BaseTask {
    async run(): Promise<TaskResult<void>> {
        if (toolchain.option.engine == 'unity' && toolchain.option.platform == 'WebGL') {
            let method: string | null = null;
            if (toolchain.option.webglRuntime == 'minigame') {
                method = 'SetAsWeixin';
            } else if (toolchain.option.webglRuntime == 'douyin') {
                method = 'SetAsDouyin';
            }

            if (method != null) {
                const params = ['-batchmode', '-projectPath', toolchain.params.workSpacePath, '-executeMethod', `BuildCommand.${method}`, '-quit'];
                await toolchain.unity.runUnityCommand(this.cmdOption, params, 'SetScriptDefine', true);
            }
        }

        return { success: true, errorCode: 0 };
    }
}
